package com.neu.service.wty;


import com.neu.dao.wty.UserDao;

import java.util.List;
import java.util.Map;

public class UserService {
    private UserDao userDao;
    public UserService(){
        userDao = new UserDao();
    }

    /**
     *
     * @param u_tel 传入的是用户输入的tel 但是管理员用的是m_no
     * @param u_pwd 同上
     *
     */
    public Map<String,Object> checkLogin(String u_tel,String u_pwd){
        Map<String,Object> map=null;
        try {
            List<Map<String,Object>> list =userDao.checkLogin(u_tel,u_pwd);
            map=list.get(0);
            //打印map中的数据 发布时按需删除
//            System.out.println(map.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    public boolean register(String u_tel,String u_pwd){
        boolean flag=false;
        try {
            int row=userDao.register(u_tel,u_pwd);
            if (row>0){
                flag=true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    public boolean alterPwdByEmail(String newPwd,String u_mail){
        boolean flag=false;
        try {
            int row=userDao.alterPwd(newPwd, u_mail);
            if (row>0){
                flag=true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }
    public boolean findByEmail(String u_email){
        boolean flag=false;
        int row=userDao.findByEmail(u_email);
        if (row>0){
            flag=true;
        }
        return flag;
    }

}
